<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error{
            border: 1px solid crimson;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="updateNewsForm">
        <br/>
        <div class="form-group">
            <label for="title">标题：</label>
            <input type="text" class="form-control" id="title" value="${news.title}" name="title" placeholder="输入标题">
        </div>
        <div class="form-group">
            <label for="contect">内容：</label>
            <input type="text" class="form-control" id="contect" value="${news.contect}" name="contect" placeholder="输入内容">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>

       <script>
           
           var updatenews=function(){
               if(!check().form()){
                   return;
               }
               $.ajax({
                   url:'news_updateNews',
                   type:'POST',
                   data:{
                       'news.title':$('#title').val(),
                       'news.contect':$('#contect').val(), 
                       'news.newId':${news.newId},
                       'news.boardId':${news.boardId},
                       'news.userId':${news.userId},
                   },
                   datatype:'json',
                   success:function (result) {
                       $('#cancelBtn').click();
                   }
               })
           }

           $('#saveBtn').click(function () {
               updatenews();
           })

           $('#cancelBtn').click(function () {
               var index = parent.layer.getFrameIndex(window.name);
               parent.getNewsList();
               parent.layer.close(index);
           })

             function  check() {
                return  $('#updateNewsForm').validate({
                     //规则
                    rules:{
                        title:{
                            required:true,
                        },
                        contect:{
                            required:true,
                        }
                    } ,
                     messages:{
                        title:{
                            required:"",
                        },
                        contect:{
                            required:"",
                        }
                     }
                 })
             }
       </script>
</body>
</html>
